<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>进行中列表</title>
    <!-- css代码 start -->
    <link href="../../../css/mui.min.css" rel="stylesheet"/>
    <link href="../../../css/global.css" rel="stylesheet"/>
    <link href="../../../css/style.css" rel="stylesheet"/>
    <link rel="stylesheet" href="../../../css/mui.picker.css">
    <link rel="stylesheet" href="../../../css/mui.poppicker.css">
    <link href="../../../css/task.css" rel="stylesheet"/>
    <style>
        #div {
            width: 0px;
            height: 0px;
            background: red;
            position: fixed;
            top: 65%;
            left: 50%;
        }

        /*移除底部或顶部三角,需要在删除此代码*/
        .mui-popover .mui-popover-arrow:after {
            width: 0px;
        }

        #div1 {
            width: 0px;
            height: 0px;
            background: red;
            position: fixed;
            top: 70%;
            left: 50%;
        }

        /*移除底部或顶部三角,需要在删除此代码*/
        .mui-popover1 .mui-popover-arrow:after {
            width: 0px;
        }

        #div6 {
            width: 0px;
            height: 0px;
            background: red;
            position: fixed;
            top: 65%;
            left: 50%;
        }

        /*移除底部或顶部三角,需要在删除此代码*/
        .mui-popover6 .mui-popover-arrow:after {
            width: 0px;
        }

        .d_int_tp {
            border: 0 !important;
            margin-top: 6px !important;
        }

        .details_con .btm .selectBtn {
            line-height: 28px;
            color: #ffffff;
            background: #ea1e1a;
        }

        .item_box .item .text {
            margin: 5px auto;
        }

        .item_box .item .text span.cen {
            margin-left: 0;
        }

        .item_box .item .text span {
            width: auto;
        }

        .select-tzstate {
            width: 100%;
            border: 0;
            color: #a9a9a9;
            font-size: 16px;
            text-align: left;
            padding: 15px;
        }

        .mui-bar-nav {
            box-shadow: 0 1px 6px #ea1e1a;
        }

        .popover .my-content-cell {
            padding: 0;
            margin: 0 10px;
        }

        .popover .arrow-right-position {
            right: -5px;
        }

        input.d_ipt {
            width: 60%;
        }
    </style>
    <!-- css代码 end -->
</head>
<body>

<!-- html代码 start -->
<!-- <div class="send_logo">
    <img src="../../../images/send_logo.png" width="100%">
</div> -->
<!-- html代码 start -->
<div id="div"></div>
<div id="popover" class="mui-popover shadow popover">
    <p class="title">请确定服务是否全部完成</p>
    <div class="btn_box">

        <span class="fl" id="noTrue">未完成</span>
        <span class="fr red" id="btnYes">已完成</span>
    </div>
</div>

<div id="div1"></div>
<div id="popover1" class="mui-popover shadow popover">
    <div class="details_con">
        <div class="my-content-cell">
            <div class="inline-block" id="pjcgqd">
                <em>查看计划安排</em>
                <span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
            </div>
        </div>
        <div class="clum" style="margin: 0 10px;">
            <span class="name">预计上门时间<em class="t_red">*</em></span>
            <button id='estimatedVisitingTime' type="button" class="selectDate">请选择时间</button>
        </div>
        <div class="clum" style="margin: 0 10px;">
            <span class="name">预计工时<em class="t_red">*</em></span>
            <input id="estimatedWorkingHours" type="number" class="d_ipt" placeholder="请输入预计工时" onchange="jisuan('1')"/>
        </div>
        <div class="clum" style="margin: 0 10px;">
            <span class="name">预计离开时间<em class="t_red">*</em></span>
            <input id="estimatedDepartureTime" type="text" class="d_ipt" placeholder="自动计算" disabled="disabled"/>
        </div>
    </div>
    <div class="btn_box">
        <span class="fl" id="closeDoor" onclick="closeDoor()">取消</span>
        <span class="fr red" id="saveDoor">确定</span>
    </div>
</div>

<div id="div6"></div>
<div id="popover6" class="mui-popover shadow popover">
    <p class="title" id="title">与您之前的工作计划时间冲突，是否确定？</p>
    <div class="btn_box">

        <span class="fl" onclick="closepop6()">取消</span>
        <span class="fr red" id="quedingupdate6">确定</span>
    </div>
</div>


<header class="mui-bar mui-bar-nav">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    <h1 id="title" class="mui-title">进行中列表</h1>
</header>
<div style="height: 30px;"></div>
<div class="mui-content m">
    <div class="details_con select_con" id="search">
        <div class="clum">
            <input type="text" class="d_int_tp" id="customerName" name="customerName" placeholder="输入客户名称"/>
        </div>
        <div class="clum">
            <!-- <input type="text" class="d_int_tp" id="serviceType" name="serviceType" placeholder="输入服务类型(子)" /> -->
            <span class="txt" style="width: 100%;">
						<input type="hidden" id="serviceTypeValue"/>
						<button id='serviceType' class="mui-btn mui-btn-block mui-btn-select select-tzstate"
                                type='button'>请选择服务子类型</button>
					</span>
        </div>
        <div class="btm autoHeight">
            <p class="selectBtn" id="searchBtn" onclick="getList()">查询</p>
        </div>
    </div>
    <div class="details_con" style="margin: 30px 0 0 0;">
        <div class="item_box" id="neirong">
        </div>
    </div>
</div>
<!-- html代码 end -->

<!-- js代码 start -->

<!-- 基础js start -->
<script src="../../../js/mui.min.js"></script>
<script src="../../../js/utils/h.js"></script>
<script src="../../../js/constant.js"></script>
<script src="../../../js/common.js"></script>
<script src="../../../js/utils/base64.js"></script>
<script src="../../../js/utils/md5.js"></script>
<script src="../../../js/utils/sortMap.js"></script>
<script src="../../../js/utils/http.js"></script>
<script src="../../../js/app.js"></script>
<!-- 基础js end -->
<script src="../../../js/sqliteTools.js"></script>
<script src="../../../js/mui.picker.js"></script>
<script src="../../../js/mui.poppicker.js"></script>
<script src="../../../js/utils/rolldate.min.js"></script>
<script type="text/javascript" charset="utf-8">
	var planIdV
    var serviceNoticeIdV
    var serviceNoV
	var customerNameV
    var estimatedVisitingTime
    var estimatedWorkingHours
    var estimatedDepartureTime
    var wcState
    var autoOutLogFlag = false

    function closepop6() {
        mui("#popover6").popover('hide', document.getElementById("div6"));
        autoOutLogFlag = false
    }

    // 页面跳转方法
    function tiaozhuan(ServiceNoticeId, serviceNo, planId, planState, subServiceType, isCheck, customerName) {
        planIdV = planId
        serviceNoticeIdV = ServiceNoticeId
        serviceNoV = serviceNo
		customerNameV = customerName
        // 不同的状态跳转到不同的页面
        if (planState == 0) { // 待接受
            app.jumpTo("/view/service/accept/details.html", "view/service/accept/details.html", {
                ServiceNoticeId: ServiceNoticeId,
                serviceNo: serviceNo,
                planId: planId
            });
        } else if (planState == 1) { // 已接受
            //已接受进入签到页面
            app.jumpTo('/view/service/notice/signIn.html', 'view/service/notice/signIn.html', {
                ServiceNoticeId: ServiceNoticeId,
                serviceNo: serviceNo,
                planId: planId
            })
        } else if (planState == 2) { // 已签到
            //判断是否写日志
            ajaxPost(BASE_URL + "cc/ServiceLog/selectServiceLogList", {
                "stPlanId": planId
            }, function (data) {
                if (data.code === 200) {
                    //如果是安装单，判断是否已核对
                    //已签到  判断服务类型是安装还是非安装
                    if (subServiceType == "安装") {
                        if (isCheck == "2") { //已核对
                            //判断有没有日志
                            if (data.data && data.data.length > 0) {
                                app.jumpTo("/view/service/notice/signOutAddReport.html", "view/service/notice/signOutAddReport.html", {
									ServiceNoticeId: ServiceNoticeId,
									serviceNo: serviceNo,
									planId: planId
								});
                            } else {                           
								app.jumpTo('/view/service/notice/signOut.html', 'view/service/notice/signOut.html', {
								    ServiceNoticeId: ServiceNoticeId,
								    serviceNo: serviceNo,
								    planId: planId
								})
                            }
                        } else { //跳转到核对页面
                            var logFlag = 1
                            if (data.data == "" || data.data.length == 0 || data.data == null || data.data == undefined) {  //没日志
                                logFlag = 0
                            }
                            app.jumpTo('/view/service/checkInstrument/checkInstrument.html', 'view/service/checkInstrument/checkInstrument.html', {
                                serviceNo: serviceNo,
                                ServiceNoticeId: ServiceNoticeId,
                                planId: planId,
                                logFlag: logFlag
                            });
                        }
                    } else {
                        if (data.data && data.data.length > 0) {
							app.jumpTo("/view/service/notice/signOutAddReport.html", "view/service/notice/signOutAddReport.html", {
							    ServiceNoticeId: ServiceNoticeId,
							    serviceNo: serviceNo,
							    planId: planId
							});
                        } else {
                            app.jumpTo('/view/service/notice/signOut.html', 'view/service/notice/signOut.html', {
                                ServiceNoticeId: ServiceNoticeId,
                                serviceNo: serviceNo,
                                planId: planId
                            });
                        }
                    }
                } else {
                    app.toast('查询日志失败')
                }
            }, function (errorMsg) {
                app.toast('查询日志失败')
            });
        } else if (planState == 3) { // 已签离
			ajaxGet(BASE_URL + "cc/PlanDetails/selectAllOldPlanDetailId", {
				"serviceNoticeId": ServiceNoticeId,
				"enginnerId": app.getUser().enginnerId
			}, function(data) {
				if(data.code == 200){
					var oldPlanId = data.data.id;
					//判断是否写日志
					ajaxPost(BASE_URL + "cc/ServiceLog/selectServiceLogList", {
					    "stPlanId": oldPlanId
					}, function (data) {
					    if (data.code === 200) {
					        if (data.data && data.data.length > 0) {  //显示添加报告
					            //已签离 跳转签到添加报告页面
					            app.jumpTo('/view/service/notice/signInAddReport.html', 'view/service/notice/signInAddReport.html', {
					                ServiceNoticeId: ServiceNoticeId,
					                serviceNo: serviceNo,
					                planId: planId
					            })
					        } else { 	//显示添加日志
					            app.jumpTo("/view/service/serviceLog/logAdd.html", "view/service/serviceLog/logAdd.html",{
									serviceNo: serviceNo,
									planId: planId,
									serviceNoticeId: ServiceNoticeId,
									listName: 'yiqianli'
								});
					        }
					    } else {
					        app.toast('查询日志失败')
					    }
					}, function (errorMsg) {
					    app.toast('查询日志失败')
					});
				}else{
					app.toast('查询失败')
				}
			}, function(errorMsg) {
				app.toast('查询失败')
			});
        } else if (planState == 4) { // 已完成 自动签离
			var oldPlanId = '';
			ajaxGet(BASE_URL + "cc/PlanDetails/selectAllOldPlanDetailId", {
				"serviceNoticeId": ServiceNoticeId,
				"enginnerId": app.getUser().enginnerId
			}, function(data) {
				if(data.code == 200){
					if (data.data && data.data.id){
						oldPlanId = data.data.id;
						// 先判断是否有已经完成且已经提交的电话解决报告，如果有跳转关闭页面，如果没有在验证日志
						ajaxGet(BASE_URL + "cc/report/info/checkPhoneResolutionReportCompleted", {
							"enginnerId": app.getUser().enginnerId,
							"planId": oldPlanId,
							"serviceNo": serviceNo
						}, function(data) {
							if(data.code==200){
								if (data.data && data.data.length > 0) {
									// 跳转电话解决报告关闭页面
									ajaxGet(BASE_URL + "cc/PlanDetails/checkPlanDetailsVisitList", { //判断是否上过门
										enginnerId: app.getUser().enginnerId,
										serviceNo: serviceNo
									}, function (data) {
										if (data.code == 200) {
											if (data.data.length) { //进报告页面
												app.jumpTo("/view/service/notice/signOutVisitAgain.html", "view/service/notice/signOutVisitAgain.html",{
													ServiceNoticeId: ServiceNoticeId,
													serviceNo: serviceNo,
													planId: planId,
													complete: 1
												});
											} else {
												// 跳转电话解决报告关闭页面
												var signClose = plus.webview.create('/view/service/notice/signClose.html', 'view/service/notice/signClose.html', null,
													{
														ServiceNoticeId: ServiceNoticeId,
														serviceNo: serviceNo,
														planId: planId
													})
												signClose.show();
											}
										} else {
											app.toast(data.msg)
										}
									}, function (errorMsg) {
										app.toast(errorMsg)
									});
								}else{
									//已完成 自动签离 先判断是否有日志  没有进日志页  有进报告页
									ajaxGet(BASE_URL + "cc/ServiceLog/getServiceLogList", {
										"enginnerId": app.getUser().enginnerId,
										"planId": oldPlanId
									}, function (data) {
										if (data.code == 200) {
											if ( data.data && data.data.length > 0) {
												 //进报告页面
												app.jumpTo("/view/service/notice/signOutVisitAgain.html", "view/service/notice/signOutVisitAgain.html", {
													ServiceNoticeId: ServiceNoticeId,
													serviceNo: serviceNo,
													planId: planId,
													complete: 1
												});
											} else {
												app.jumpTo("/view/service/serviceLog/logAdd.html", "view/service/serviceLog/logAdd.html", {
													serviceNoticeId: ServiceNoticeId,
													serviceNo: serviceNo,
													planId: planId,
													listName: "checkedOutList"
												});
											}
										} else {
											app.toast(data.msg)
										}
									}, function (errorMsg) {
										app.toast(errorMsg)
									});
								}
							}else{
								app.toast(data.msg)
							}
						}, function(errorMsg) {
							app.toast(errorMsg)
						});
					} else {
						// 跳转电话解决报告关闭页面
						var signClose = plus.webview.create('/view/service/notice/signClose.html', 'view/service/notice/signClose.html', null,
						    {
						        ServiceNoticeId: ServiceNoticeId,
						        serviceNo: serviceNo,
						        planId: planId
						    })
						signClose.show();
					}
				}else{
					app.toast('查询失败')
				}
			}, function(errorMsg) {
				app.toast('查询失败')
			});
        } else if (planState == 5) {// 自动签离
			// 查询是否有已提交并且服务状态为已完成的服务报告
			ajaxGet(BASE_URL + "cc/report/info/checkReportResult", {
				"serviceNo": serviceNo
			}, function(data) {
				app.closeWaiting()
				if (data.code === 200) {
					if (data.data && data.data.length > 0) {
						wcState = "yiwancheng"
						findLog()
					} else {
						mui("#popover").popover('toggle', document.getElementById("div"));
					}
				} else {
					app.toast(data.msg)
				}
			}, function(errorMsg) {
				app.closeWaiting()
				app.toast(errorMsg)
			});
        }
    }

    // 获取列表的方法
    function getList() {
        app.showWaiting('加载中...')

        var customerName = h("#customerName").val();
        var serviceType = h("#serviceType").html();
        if (serviceType == '请选择服务子类型') {
            serviceType = ""
        }
        ajaxGet(BASE_URL + "cc/notice/getMyServiceNotice", {
            "EnginnerId": app.getUser().enginnerId,
            "state": "1",
            "customerName": customerName,
            "serviceType": serviceType
        }, function (data) {
            app.closeWaiting()
            if (data.code == 200) {
                h("#neirong").html("");
                var html = "";
                if (data.data && data.data.length > 0) {
                    for (var i = 0; i < data.data.length; i++) {
                        /* var xianshi = '';
                        var enginnerType = data.data[i].enginnerType==undefined?"":data.data[i].enginnerType;
                        var isVip = data.data[i].isVip==undefined?"":data.data[i].isVip;
                        var userIsdpel = data.data[i].userIsdpel==undefined?"":data.data[i].userIsdpel;

                        if(userIsdpel=='1'){
                            xianshi = ''
                        }
                        if(isVip!=''){
                            xianshi += isVip
                        }else{
                            if(enginnerType!=''){
                                xianshi += enginnerType
                            }
                        } */

                        var enginnerType = data.data[i].enginnerType ? data.data[i].enginnerType : "";
                        var hopeBusinessHours = data.data[i].hopeBusinessHours ? data.data[i].hopeBusinessHours : "";
                        html += '<div class="item" onclick="tiaozhuan(\'' + data.data[i].id + '\',\'' + data.data[i].serviceNo +
                            '\',\'' + data.data[i].planId + '\',\'' + data.data[i].planState + '\',\'' + data.data[i].subServiceType +
                            '\',\'' + data.data[i].isCheck + '\',\'' + data.data[i].customerName + '\')">';
                        html += '<div class="bar">';
                        html += '<span class="number"><img src="../../../images/icon_204.png" />' + data.data[i].serviceNo + '</span>';
                        html += '<span class="vip">' + enginnerType + '</span>';
                        html += '</div>';
                        html += '<div class="text autoHeight">';
                        html += '<span class="cen" style="color: #333;">' + data.data[i].customerName + '</span>';
                        html += '</div>';
                        html += '<div class="type">';
                        html += '<p><img src="../../../images/icon_202.png"/><span class="lpl">提交时间：</span><span>' + data.data[i].createTime + '</span></p>';
                        html += '<p><img src="../../../images/icon_203.png"/><span class="lpl">服务子类型：</span><span>' + data.data[i].subServiceType + '</span></p>';
                        html += '<p><img src="../../../images/icon_202.png"/><span class="lpl">期望服务时间：</span><span>' + hopeBusinessHours + '</span></p>';

                        var planState = ""
                        if (data.data[i].planState == 0) {
                            planState = "待接受"
                        } else if (data.data[i].planState == 1) {
                            planState = "已接受"
                        } else if (data.data[i].planState == 2) {
                            planState = "已签到"
                        } else if (data.data[i].planState == 3) {
                            planState = "已签离"
                        } else if (data.data[i].planState == 4) {
                            planState = "已完成"
                        } else if (data.data[i].planState == 5) {
                            planState = "自动签离"
                        }
                        html += '<p class="icon2"><img src="../../../images/icon_205.png"/>状态：<span>' + planState + '</span></p>'
                        if (data.data[i].subServiceType == "安装") {
                            if (data.data[i].isCheck == "2") { //已核对
                                html += '<p class="icon2"><img src="../../../images/icon_368.png"/><span>序列号已核对</span></p>';
                            } else {
                                html += '<p class="icon2"><img src="../../../images/icon_368.png"/><span>序列号未核对</span></p>';
                            }
                        }

                        html += '</div>';
                        html += '</div>';


                    }
                    h("#neirong").html(html);
                } else {
                    html = '<div class="nodata">—— 暂无数据 ——</div>';
                    h("#neirong").html(html);
                }
            } else {
				var html = '<div class="nodata">—— 暂无数据 ——</div>';
				h("#neirong").html(html);
				app.toast(data.msg);
			}
        }, function (errorMsg) {
			app.closeWaiting();
			var html = '<div class="nodata">—— 暂无数据 ——</div>';
			h("#neirong").html(html);
			app.toast("数据获取失败，请检查网络连接");	
		});
    }

    (function ($, doc) {
        $.init();

        new Rolldate({
            el: '#estimatedVisitingTime',
            format: 'YYYY-MM-DD hh:mm',
            beginYear: 2015,
            endYear: 2050,
            trigger: 'click',
            lang: {
                title: '请选择预计上门时间',
            },
            confirm: function (date) {
                jisuan(date)
            }
        })

        $.plusReady(function () {
            // 调用获取列表的方法
            getList()

            // 查看计划安排
            h("#pjcgqd").tap(function () {
                app.jumpTo("/view/service/taskDetails/task_details.html", "view/service/taskDetails/task_details.html",
                    {
                        serviceNoticeId: serviceNoticeIdV,
                        serviceNo: serviceNoV,
                        enginnerId: app.getUser().enginnerId
                    }
                );
            });

            // 服务子类型下拉
            h('#serviceType').tap(function () {
                var userPicker = new $.PopPicker();
                ajaxGetJson(BASE_URL + 'cc/dict/selectCCDict', {
                    tableName: 'snsubtype',
                    engineerId: app.getUser().enginnerId
                }, function (data) {
                    if (!data) {
                        app.toast("无下拉内容")
                        return
                    }
                    // 数组指定位置插入数据
                    data.splice(0, 0, {"text": "请选择服务子类型", "value": ""});
                    userPicker.setData(data);
                    userPicker.show(function (items) {
                        h('#serviceType').html(items[0].text)
                        h('#serviceTypeValue').val(items[0].value)
                        userPicker.dispose()
                    });
                });
            });

            // 确定完成全部服务  签离操作
            h("#btnYes").tap(function () {
                mui("#popover").popover('hide', document.getElementById("div"));
                wcState = "yiwancheng"
                findLog()
                return false
            });

            // 取消操作
            h("#noTrue").tap(function () {
                mui("#popover").popover('hide', document.getElementById("div"));
                // mui("#popover1").popover('toggle', document.getElementById("div1"));
                wcState = "weiwancheng"
                findLog()
                return false
            });

            h("#saveDoor").tap(function () {
                app.showWaiting('正在提交...')

                // 调用计算方法
                jisuan('1');
                estimatedVisitingTime = h("#estimatedVisitingTime").html();
                if (estimatedVisitingTime == null || estimatedVisitingTime == "" || estimatedVisitingTime == "请选择时间") {
                    app.closeWaiting()
                    app.toast("请选择预计上门时间");
                    return
                }
                estimatedWorkingHours = h("#estimatedWorkingHours").val();
                if (estimatedWorkingHours == null || estimatedWorkingHours == "") {
                    app.closeWaiting()
                    app.toast("请输入预计工时");
                    return
                }
                estimatedDepartureTime = h("#estimatedDepartureTime").val();

                var evt = stringYYYYMMDDHHMMToDate(estimatedVisitingTime).getTime();
                var newDate = new Date().getTime();
                if (evt <= newDate) {
                    app.closeWaiting()
                    app.toast("预计上门时间不可以小于当前时间");
                    return
                }

                ajaxGet(BASE_URL + "cc/PlanDetails/checkPlanDetailsList", {
                    "enginnerId": app.getUser().enginnerId,
                    "estimatedVisitingTime": estimatedVisitingTime,
                    "estimatedDepartureTime": estimatedDepartureTime,
                    "planId": planIdV
                }, function (data) {
                    if (data.code == 200) {
                        saveIn()
                    } else {
                        app.closeWaiting()
                        mui("#popover6").popover('toggle', document.getElementById("div6"));
                    }
                }, function (errorMsg) {
                    app.closeWaiting()
                    app.toast(errorMsg)
                });
            });

            h("#quedingupdate6").tap(function () {
                app.showWaiting('正在提交...')
                saveIn()
                return false
            })

            // 取消方法 关闭弹窗
            h("#closeDoor").tap(function () {
                mui("#popover").popover('hide', document.getElementById("div"));
                mui("#popover1").popover('hide', document.getElementById("div1"));
                autoOutLogFlag = false
            })

            h('.mui-action-back').tap(function () {
                var indexTl = plus.webview.getWebviewById('view/main/indexTL.html');
                if (indexTl) {
                    indexTl.evalJS('getMyTeamCount()')
                }
            })
        });

    }(mui, document));

    function saveIn() {
        ajaxGet(BASE_URL + "cc/PlanDetails/fseSignOffAutoAgain", {
            "serviceNoticeId": serviceNoticeIdV,
            "serviceNo": serviceNoV,
            "enginnerId": app.getUser().enginnerId,
            "planId": planIdV,
            "estimatedVisitingTime": estimatedVisitingTime,
            "estimatedWorkingHours": estimatedWorkingHours,
            "estimatedDepartureTime": estimatedDepartureTime
        }, function (data) {
            app.closeWaiting()
            if (data.code == 200) {
                
                mui("#popover").popover('hide', document.getElementById("div"));
                mui("#popover1").popover('hide', document.getElementById("div1"));
                mui("#popover6").popover('hide', document.getElementById("div6"));
				
				if(data.data && data.data.length > 0){
					// 判断是否存在离线数据，
					var enginnerId = app.getUser().enginnerId;
					var fseName = app.getUser().name;
					var sqliteTool = new sqliteTools(); 
					sqliteTool.openDatabase();
					for (var i = 0; i < data.data.length; i++) {
						var resData = data.data[i];		
						sqliteTool.selectServiceByNoticeId(enginnerId, resData.serviceNoticeId, resData, function(flag, offlineData, callBackData) {
							if(flag){
								if (offlineData && offlineData.length > 0) {
									if(callBackData.state == "4"){
										sqliteTool.deleteServiceData(offlineData[0].planId, function(flag) {
											console.log("删除本地数据"+flag)
										})
									} else {
										sqliteTool.insertServiceSignOffAginData(offlineData[0].id, callBackData.planId, function(flag) {
											console.log("更新计划数据"+flag)
										})
									}
								} else {
									sqliteTool.insertServiceBaseData(callBackData.serviceNo, callBackData.serviceNoticeId, callBackData.planId, customerNameV, callBackData.instrumentId, callBackData.instSn, callBackData.acceptTime, enginnerId, fseName, callBackData.serviceType, callBackData.subServiceType, function (flag) {
										console.log("插入计划数据"+flag)
									})
								}
							}	
						});
					}
					setTimeout(function() {
						sqliteTool.closeDB();
					}, 200);				
				}
				app.toast('操作成功')
                // var assignList = plus.webview.getWebviewById('view/service/assign/conductList.html');
                // assignList.evalJS('getList()')

                // 20200525 修复文档（客户提出20200524测试反馈）93：自动签离的服务页面跳转见“参考-页面跳转6.1”，填写工作日志之后应有相应的页面跳转5.1.2/5.1.3，而不是直接跳转到待接受列表。
                /* var indexFSE = plus.webview.getWebviewById('view/main/indexFSE.html');
                if(indexFSE){
                    indexFSE.evalJS('getList("1")')
                }
                var self = plus.webview.currentWebview();
                var checkedOutList = plus.webview.getWebviewById('view/service/notice/checkedOutList.html');
                if(checkedOutList){
                    checkedOutList.evalJS('getList()')
                    mui.back()
                }else{
                    var checkedOutList1 = plus.webview.create('/view/service/notice/checkedOutList.html','view/service/notice/checkedOutList.html')
                    checkedOutList1.show()
                    self.close();
                } */
                getList()

                if (autoOutLogFlag) {
                    // quanbuwanchengOnlysave();
                    app.jumpTo("/view/service/serviceLog/logAdd.html", "view/service/serviceLog/logAdd.html",
                        {
                            serviceNoticeId: serviceNoticeIdV,
                            serviceNo: serviceNoV,
                            planId: planIdV,
                            checkOutList: true,
                        });
                    autoOutLogFlag = false
                    return
                }
                // 5.1.3已填写工作日志，服务通知状态为：已签离 （页面含添加报告、签离按钮）
                app.jumpTo("/view/service/notice/signInAddReport.html", "view/service/notice/signInAddReport.html", {
                    ServiceNoticeId: serviceNoticeIdV,
                    serviceNo: serviceNoV,
                    planId: planIdV
                });
            } else {
                app.toast(data.msg)
            }
        }, function (errorMsg) {
            app.closeWaiting()
            app.toast('操作失败')
        });
    }

    // 自动计算方法
    function jisuan(date) {
        var estimatedVisitingTime;
        if (date != "1") {
            estimatedVisitingTime = date
        } else {
            estimatedVisitingTime = h("#estimatedVisitingTime").html();
        }
        if (estimatedVisitingTime == null || estimatedVisitingTime == "" || estimatedVisitingTime == "请选择时间") {
            return
        }
        var evt = stringYYYYMMDDHHMMToDate(estimatedVisitingTime).getTime();
        var estimatedWorkingHours = h("#estimatedWorkingHours").val();
        if (estimatedWorkingHours == null || estimatedWorkingHours == "") {
            return
        }
        var edt = evt + estimatedWorkingHours * 60 * 60 * 1000;
        var estimatedDepartureTime = new Date(edt).Format("yyyy-MM-dd HH:mm");
        h("#estimatedDepartureTime").val(estimatedDepartureTime);
    }

    //判断是否有日志，没有进日志页面，有进报告页面
    function findLog() {
        ajaxGet(BASE_URL + "cc/ServiceLog/getServiceLogList", {
            "enginnerId": app.getUser().enginnerId,
            "planId": planIdV
        }, function (data) {
            if (data.code == 200) {
				if (data.data.length > 0){
					if (wcState == "yiwancheng") {
					    quanbuwancheng();
					} else if (wcState == "weiwancheng") {
					    mui("#popover1").popover('toggle', document.getElementById("div1"));
					}
				} else {
					if (wcState == "yiwancheng") {
					    quanbuwanchengOnlysave();
					    app.jumpTo("/view/service/serviceLog/logAdd.html", "view/service/serviceLog/logAdd.html",{
					    	serviceNoticeId: serviceNoticeIdV,
					    	serviceNo: serviceNoV,
					    	planId: planIdV,
					    	listName: "autoSignOut"
					    });
					} else if (wcState == "weiwancheng") {
					    mui("#popover1").popover('toggle', document.getElementById("div1"));
					    autoOutLogFlag = true
					}
				}
            } else {
                app.toast(data.msg)
            }
        }, function (errorMsg) {
            app.toast(errorMsg)
        });
    }

    // 全部完成方法
    function quanbuwancheng() {
        app.showWaiting('正在提交...')
        ajaxGet(BASE_URL + "cc/PlanDetails/signOffAutoState", {
            "serviceNoticeId": serviceNoticeIdV,
            "planId": planIdV,
            "enginnerId": app.getUser().enginnerId
        }, function (data) {
            app.closeWaiting()
            if (data.code == 200) {
				if(data.data && data.data.length > 0){
					// 判断是否存在离线数据，
					var enginnerId = app.getUser().enginnerId;
					var sqliteTool = new sqliteTools();
					sqliteTool.openDatabase();
					for (var i = 0; i < data.data.length; i++) {
						var resData = data.data[i];				
						sqliteTool.selectServiceByPlanId(enginnerId, resData.planId, resData, function(flag, offlineData, callBackData) {
							if (offlineData && offlineData.length > 0) {
								sqliteTool.deleteServiceData(offlineData.planId, function(flag) {
									console.log("删除本地数据"+flag)
								})
							}									
						});
					}
					setTimeout(function() {
						sqliteTool.closeDB();
					}, 200);
				}
				
                getList()
                app.toast('操作成功')
            } else {
                app.toast('操作失败')
            }
            mui("#popover").popover('hide', document.getElementById("div"));
            // var assignList = plus.webview.getWebviewById('view/service/assign/conductList.html');
            // assignList.evalJS('getList()')

            // 20200525 修复文档（客户提出20200524测试反馈）93：自动签离的服务页面跳转见“参考-页面跳转6.1”，填写工作日志之后应有相应的页面跳转5.1.2/5.1.3，而不是直接跳转到待接受列表。
            /* var indexFSE = plus.webview.getWebviewById('view/main/indexFSE.html');
            if(indexFSE){
                indexFSE.evalJS('getList("1")')
            }
            var self = plus.webview.currentWebview();
            var completedList = plus.webview.getWebviewById('view/service/notice/completedList.html');
            if(completedList){
                completedList.evalJS('initData()')
                mui.back()
            }else{
                var completedList1 = plus.webview.create('/view/service/notice/completedList.html','view/service/notice/completedList.html')
                completedList1.show()
                self.close();
            } */

            // 文档要求：5.1.2已填写工作日志，服务通知状态为：已完成（页面含添加报告、还需再次上门按钮）
            app.jumpTo("/view/service/notice/signOutVisitAgain.html", "view/service/notice/signOutVisitAgain.html",
                {
                    ServiceNoticeId: serviceNoticeIdV,
                    serviceNo: serviceNoV,
                    planId: planIdV,
					complete: 1
                });
        }, function (errorMsg) {
            app.closeWaiting()
            app.toast('操作失败')
        });
    }

    // 全部完成方法 （只保存 不跳页）
    function quanbuwanchengOnlysave() {
        app.showWaiting('正在提交...')
        ajaxGet(BASE_URL + "cc/PlanDetails/signOffAutoState", {
            "serviceNoticeId": serviceNoticeIdV,
            "planId": planIdV,
            "enginnerId": app.getUser().enginnerId
        }, function (data) {
            app.closeWaiting();
			if(data.data && data.data.length > 0){
				// 判断是否存在离线数据，
				var enginnerId = app.getUser().enginnerId;
				var sqliteTool = new sqliteTools(); 
				sqliteTool.openDatabase();
				for (var i = 0; i < data.data.length; i++) {
					var resData = data.data[i];			
					sqliteTool.selectServiceByPlanId(enginnerId, resData.planId, resData, function(flag, offlineData, callBackData) {
						if (offlineData && offlineData.length > 0) {
							sqliteTool.deleteServiceData(offlineData.planId, function(flag) {
								console.log("删除本地数据"+flag)
							})
						}									
					});
				}	
				setTimeout(function() {
					sqliteTool.closeDB();
				}, 200);
			}
            getList();
        }, function (errorMsg) {
            app.closeWaiting()
            app.toast('操作失败')
        });
    }
</script>
<!-- js代码 end -->
</body>
</html>
